package com.spic.business.violation.supervision.speed.controller;

import com.spic.business.common.core.utils.poi.BusinessExcelUtil;
import com.spic.business.violation.supervision.speed.domain.ViolationsVehicleManagement;
import com.spic.business.violation.supervision.speed.service.IViolationsVehicleManagementService;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 车辆管理Controller
 *
 * @author yangjie
 * @date 2021-10-12
 */
@RestController
@RequestMapping("/violation/management")
public class ViolationsVehicleManagementController extends BaseController
{
    @Autowired
    private IViolationsVehicleManagementService violationsVehicleManagementService;

    /**
     * 查询车辆管理列表
     */
    @PreAuthorize(hasPermi = "business/violation:management:list")
    @GetMapping("/list")
    public TableDataInfo list(ViolationsVehicleManagement violationsVehicleManagement)
    {
        startPage();
        List<ViolationsVehicleManagement> list = violationsVehicleManagementService.selectViolationsVehicleManagementList(violationsVehicleManagement);
        return getDataTable(list);
    }

    /**
     * 导出车辆管理列表
     */
    @PreAuthorize(hasPermi = "business/violation:management:export")
    @Log(title = "车辆管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ViolationsVehicleManagement violationsVehicleManagement) throws IOException
    {
        List<ViolationsVehicleManagement> list = violationsVehicleManagementService.selectViolationsVehicleManagementList(violationsVehicleManagement);
        ExcelUtil<ViolationsVehicleManagement> util = new BusinessExcelUtil<ViolationsVehicleManagement>(ViolationsVehicleManagement.class);
        util.exportExcel(response, list, "车辆管理数据");
    }

    /**
     * 获取车辆管理详细信息
     */
    @PreAuthorize(hasPermi = "business/violation:management:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(violationsVehicleManagementService.selectViolationsVehicleManagementById(id));
    }

    /**
     * 新增车辆管理
     */
    @PreAuthorize(hasPermi = "business/violation:management:add")
    @Log(title = "车辆管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ViolationsVehicleManagement violationsVehicleManagement)
    {
        return toAjax(violationsVehicleManagementService.insertViolationsVehicleManagement(violationsVehicleManagement));
    }

    /**
     * 修改车辆管理
     */
    @PreAuthorize(hasPermi = "business/violation:management:edit")
    @Log(title = "车辆管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ViolationsVehicleManagement violationsVehicleManagement)
    {
        return toAjax(violationsVehicleManagementService.updateViolationsVehicleManagement(violationsVehicleManagement));
    }

    /**
     * 删除车辆管理
     */
    @PreAuthorize(hasPermi = "business/violation:management:remove")
    @Log(title = "车辆管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(violationsVehicleManagementService.deleteViolationsVehicleManagementByIds(ids));
    }
    //车辆入库
    @PostMapping("/saveVehicle")
    public AjaxResult saveVehicle(){
        violationsVehicleManagementService.saveVehicle();
        return AjaxResult.success();
    }
}
